def fn(ls: Array[Int], n: Int) = {
  val nls = for (i <- ls if i < n) yield { i }
  if (nls.isEmpty) 0 else nls.sum.toDouble / nls.length.toDouble
}
